// ==UserScript==
// @Propszt Istvan
// @Import/Export file  
// ==/UserScript==

function openIEWindow() {
   window.openDialog("chrome://Calendar/content/XulFiles/importExportForm.xul", "_blank", "chrome,modal,centerscreen,resizable=yes");
}

function exportF(s) {
   window.alert(s);
   var n = s.lastIndexOf("\\");
   var loc = s.substring(0,n+1);
   var name = s.substring(n+1,s.length);
   print(n + "\n");
   print(loc + "\n");
   print(name + "\n");
   var file = IO.getFile(loc,name);
   file.append(s);
   if (!file.exists())
       file.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
   var stream = IO.newOutputStream(file, "text write create truncate");
   var i = 0;
   for (i = 0; i < 5; i++){
      stream.writeString("Sor : "+i);
   }
   stream.close();
}

function importF(s){
    window.alert(s);
    
    const nsIFilePicker = Components.interfaces.nsIFilePicker;
    var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
    fp.init(window, "Select a File", nsIFilePicker.modeOpen);
    var rv = fp.show();
    
    if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) {
        var file = fp.file;
        var path = fp.file.path;

        var stream = IO.newInputStream(file, "text");
        var json = stream.readString(10);
        stream.close();
        window.alert(json);
    }
    else{
        window.alert("Error");
    }
}

function openF(){
    const nsIFilePicker = Components.interfaces.nsIFilePicker;
    var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
    fp.init(window, "Select a File", nsIFilePicker.modeOpen);
    fp.show();
}